/**
 * file
 */
package com.tdkj.action.front.member.risevalue;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;

import com.opensymphony.xwork2.ActionContext;
import com.tdkj.action.BaseAction;
import com.tdkj.model.risevalue.BeanPlateSMSCustom;
import com.tdkj.model.risevalue.BeanPlateSMSSubscription;
import com.tdkj.model.user.BeanUser;
import com.tdkj.service.risevalue.IBeanPlateSMSCustomService;
import com.tdkj.service.risevalue.IBeanPlateSMSSubscriptionService;
import com.tdkj.util.PublicConfing;

public class PlateSMSAction extends BaseAction {
	
	private Long customId ;

	private IBeanPlateSMSCustomService plateSMSCustomService;
	
	private IBeanPlateSMSSubscriptionService plateSMSCustomSubscriptionService;
	
	private List<BeanPlateSMSCustom> customs;
	
	private List<BeanPlateSMSSubscription> subscriptions;
	
	
	public String execute(){
		BeanUser user  = (BeanUser)ActionContext.getContext().getSession().get(PublicConfing.MEMBER_MEMBWE_OBJ_STRING_CONFIG);
		Long userId = user.getId();
		
		customs = plateSMSCustomService.getAll();
		
		subscriptions = plateSMSCustomSubscriptionService.getByUserId(userId);
		
		Criteria criteria = this.createCriteria(BeanPlateSMSCustom.class);
		//加限制条件，只处理用户相关
		criteria.addOrder(Order.desc("createTime"));// 对状态进行排序
		this.queryByPage(criteria, "plateSMSAction.action", 10);

		
		return "success";
	}
	
	public String subscription(){
		BeanUser user  = (BeanUser)ActionContext.getContext().getSession().get(PublicConfing.MEMBER_MEMBWE_OBJ_STRING_CONFIG);
		Long userId = user.getId();
		
		plateSMSCustomSubscriptionService.createSubscription(userId, customId);
		
		return execute();
	}

	/**
	 * @return the customId
	 */
	public Long getCustomId() {
		return customId;
	}

	/**
	 * @param customId the customId to set
	 */
	public void setCustomId(Long customId) {
		this.customId = customId;
	}

	/**
	 * @return the customs
	 */
	public List<BeanPlateSMSCustom> getCustoms() {
		return customs;
	}

	/**
	 * @param customs the customs to set
	 */
	public void setCustoms(List<BeanPlateSMSCustom> customs) {
		this.customs = customs;
	}

	/**
	 * @return the subscriptions
	 */
	public List<BeanPlateSMSSubscription> getSubscriptions() {
		return subscriptions;
	}

	/**
	 * @param subscriptions the subscriptions to set
	 */
	public void setSubscriptions(List<BeanPlateSMSSubscription> subscriptions) {
		this.subscriptions = subscriptions;
	}

	/**
	 * @param plateSMSCustomService the plateSMSCustomService to set
	 */
	@Resource
	public void setPlateSMSCustomService(
			IBeanPlateSMSCustomService plateSMSCustomService) {
		this.plateSMSCustomService = plateSMSCustomService;
	}

	/**
	 * @param plateSMSCustomSubscriptionService the plateSMSCustomSubscriptionService to set
	 */
	@Resource
	public void setPlateSMSCustomSubscriptionService(
			IBeanPlateSMSSubscriptionService plateSMSCustomSubscriptionService) {
		this.plateSMSCustomSubscriptionService = plateSMSCustomSubscriptionService;
	}
	
	
	
}
